	<?php
class chatModel extends appModel{
	/**
	 *获得一条微信record记录
	 */
	public function get_record($id)
	{
		if(!$id)
		{
			return false;
		}
		$sql = "SELECT *,nickname as name FROM ".$this->table('wxusers')." WHERE wxid =".$id;
		$result=$this->getRow($sql);
	
		if($result)
		{
	
			return $result;
		}
		else
		{
			return false;
		}
	}
	
	public function create_record($info){
		$result=array('error'=>0,'content'=>'吐槽失败');
		$time = $_SERVER['REQUEST_TIME'];
		if($info['wxid']>0)
		{
			$sql="SELECT count(*) FROM ".$this->table('chat_silence_user')." WHERE wxid=".$info['wxid']." AND endTime>=".$time;
			$num = $this->getOne($sql);
			if($num){
				$result['error'] = 4004;
				return $result;//该用户被禁言
			}
			$sql ="SELECT * FROM ".$this->table('chat_keyword');
			$keyword = $this->getAll($sql);
			foreach ($keyword as $k=>$v){
				if(stripos($info['comment'],$keyword[$k]['keyword']) === false){ //不包含
					
				}else{ //包含
					$result['error'] = 2002;
					return $result;//
				}
			}
		}
		else
		{
			$result['error'] = 3003;
			return $result;//失败
		}
	
		$field='';
		$value='';
		foreach($info as $k=>$v)
		{	
			if($v!='')
			{
				$field.="$k,";
				$value.="'$v',";
	
			}
		}
	
		$field.=" addtime ";
		$value.=time();
		$sql="INSERT INTO ".$this->table('chat_record')." (".$field.") VALUES(".$value.")";
		$res=$this->query($sql);
		if($res){
			$result['error'] = 1;
			$result['content'] = '';
			$endTime = strtotime(date( 'Y-m-d 23:59:59',time()));
			$startTime = strtotime(date( 'Y-m-d', time()));
			$sql = "SELECT COUNT(*) FROM ".$this->table('chat_record')." WHERE wxid = ".$info['wxid']." AND addtime>=$startTime AND addtime<=$endTime";
			$num = $this->getOne($sql);
			$sql = "SELECT * FROM (SELECT q3.special_id FROM ".$this->table("chat_special_rule")." q3 WHERE q3.status = 2 AND comment_num= $num )q2";
			$sql = $sql." LEFT JOIN ".$this->table("chat_special")." q1 ON q2.special_id = q1.id";
			$res2 = $this->getAll($sql);
			if($res2){
				$result['content'] = $res2;
			}
		}
		return $result;
	
	}
	
	public function get_timestamp()
	{
		$sql="SELECT op_value FROM ".$this->table('options')." WHERE op_key='timestamp'";
		$is_appid=$this->getOne($sql);
		return  $is_appid;
	}
	public function get_refreshtime()
	{
		$sql="SELECT op_value FROM ".$this->table('options')." WHERE op_key='refreshtime'";
		$is_appid=$this->getOne($sql);
		return  $is_appid;
	}
	public function get_indexad($block_id){
		$sql = "SELECT id,title,description,pic_path,created,url FROM ".$this->table('block_content')." WHERE block_id=".$block_id." ORDER BY ordering desc";
		$result = $this->getAll($sql);
		foreach ($result as $k=>$v){
			$result[$k]['title'] = hy_dig_filter($v['title']);
			$result[$k]['description'] = hy_dig_filter($v['description']);
		}
		return $result;
	}
	public function add_click_num($block_id){
		$sql=" UPDATE ".$this->table('block_content')." SET clickNum=clickNum+1 WHERE id=".$block_id;
		$res = $this->query($sql);
		if(!$res){
			return false;
		}else{
			return true;
		}
	}
	
	public function get_special_chat($wxid){
		$sql ="SELECT q2.showtime,q1.color,q1.pic_url,q1.group_id,q1.title,q1.source_url,q1.hongbao_id FROM (SELECT q3.special_id,q3.showtime FROM ".$this->table("chat_special_rule")." q3 WHERE q3.status = 1 )q2";
		$sql = $sql." LEFT JOIN ".$this->table("chat_special")." q1 ON q2.special_id = q1.id";
// 		$sql = "SELECT q1.*,q2.showtime FROM ".$this->table("chat_special")." q1,".$this->table("chat_special_rule")." q2 WHERE q1.id=q2.special_id and q1.id in ";
// 		$sql=$sql." (select special_id from ".$this->table("chat_special_rule")." q3 WHERE q3.status = 1) ";
		$res = $this->getAll($sql);
		$_top= 1;
		foreach ($res as $k=>$v){
			$_top=$_top+15;
			if($_top>=85){
				$_top=1;
			}
			$res[$k]['top']=$_top;
		}
		$endTime = strtotime(date( 'Y-m-d 23:59:59',time()));
		$startTime = strtotime(date( 'Y-m-d', time()));
		$sql = "SELECT COUNT(*) FROM ".$this->table('chat_record')." WHERE wxid = $wxid AND addtime>=$startTime AND addtime<=$endTime";
		$num = $this->getOne($sql);
		$sql = "SELECT q1.color,q1.pic_url,q1.group_id,q1.title,q1.source_url,q1.hongbao_id FROM (SELECT q3.special_id FROM ".$this->table("chat_special_rule")." q3 WHERE q3.status = 2 AND comment_num<= $num )q2";
		$sql = $sql." LEFT JOIN ".$this->table("chat_special")." q1 ON q2.special_id = q1.id";
		$res2 = $this->getAll($sql);
		foreach ($res2 as $k=>$v){
			$_top=$_top+15;
			if($_top>=85){
				$_top=1;
			}
			$res2[$k]['top']=$_top;
		}
		//每日
		$sql ="SELECT q2.specific_time,q1.color,q1.pic_url,q1.group_id,q1.title,q1.source_url,q2.time,q1.hongbao_id FROM (SELECT q3.special_id,q3.specific_time,q3.time FROM ".$this->table("chat_special_rule")." q3 WHERE q3.status = 3 )q2";
		$sql = $sql." LEFT JOIN ".$this->table("chat_special")." q1 ON q2.special_id = q1.id";
		$res3 = $this->getAll($sql);
		$res5 = array();
		$time = $_SERVER['REQUEST_TIME'];
		foreach ($res3 as $k=>$v){
			$_top=$_top+15;
			if($_top>=85){
				$_top=1;
			}
			
			$hms =date("H:i:s", $res3[$k]['specific_time']);
			if(time()<=strtotime(date( 'Y-m-d '.$hms, $time))){
				$res5[$k] = $res3[$k];
				$res5[$k]['top']=$_top;
				$res5[$k]['specific_time']=strtotime(date( 'Y-m-d '.$hms, $time));
			}
		}
		
		//单日
		$sql ="SELECT q2.specific_time,q1.color,q1.pic_url,q1.group_id,q1.title,q1.source_url,q2.time,q1.hongbao_id  FROM (SELECT q3.special_id,q3.specific_time,q3.time FROM ".$this->table("chat_special_rule")." q3 WHERE q3.status = 4 AND q3.specific_time>=$time )q2";
		$sql = $sql." LEFT JOIN ".$this->table("chat_special")." q1 ON q2.special_id = q1.id";
		$res4 = $this->getAll($sql);
		foreach ($res4 as $k=>$v){
			$_top=$_top+15;
			if($_top>=85){
				$_top=1;
			}
			$res4[$k]['top']=$_top;
		}
		$result['rule1'] = $res;
		$result['rule2'] = $res2;
		$result['rule3'] = $res5;
		$result['rule4'] = $res4;
		return $result;
	}
	//angularjs
	public function get_special_chat2($wxid){
		//时间
		$sql ="SELECT q2.showtime,q1.color,q1.pic_url,q1.group_id,q1.title,q1.source_url,q1.hongbao_id FROM (SELECT q3.special_id,q3.showtime FROM ".$this->table("chat_special_rule")." q3 WHERE q3.status = 1 )q2";
		$sql = $sql." LEFT JOIN ".$this->table("chat_special")." q1 ON q2.special_id = q1.id";
		// 		$sql = "SELECT q1.*,q2.showtime FROM ".$this->table("chat_special")." q1,".$this->table("chat_special_rule")." q2 WHERE q1.id=q2.special_id and q1.id in ";
		// 		$sql=$sql." (select special_id from ".$this->table("chat_special_rule")." q3 WHERE q3.status = 1) ";
		$res = $this->getAll($sql);
		$_top= 1;
		foreach ($res as $k=>$v){
			$_top=$_top+15;
			if($_top+15>=85){
				$_top=1;
			}
			$res[$k]['top']=$_top;
			$res[$k]['speed']=8*(lcg_value()+1);
			$res[$k]['delay']=$res[$k]['showtime'];
		}
		$endTime = strtotime(date( 'Y-m-d 23:59:59',time()));
		$startTime = strtotime(date( 'Y-m-d', time()));
		$sql = "SELECT COUNT(*) FROM ".$this->table('chat_record')." WHERE wxid = $wxid AND addtime>=$startTime AND addtime<=$endTime";
		$num = $this->getOne($sql);
		$sql = "SELECT q1.color,q1.pic_url,q1.group_id,q1.title,q1.source_url,q1.hongbao_id FROM (SELECT q3.special_id FROM ".$this->table("chat_special_rule")." q3 WHERE q3.status = 2 AND comment_num<= $num )q2";
		$sql = $sql." LEFT JOIN ".$this->table("chat_special")." q1 ON q2.special_id = q1.id";
		$res2 = $this->getAll($sql);
		foreach ($res2 as $k=>$v){
			$_top=$_top+15;
			if($_top+15>=85){
				$_top=1;
			}
			$res2[$k]['top']=$_top;
			$res2[$k]['speed']=8*(lcg_value()+1);
			$res2[$k]['delay'] = 10+8*(lcg_value()+1);
		}
		//每日
		$sql ="SELECT q2.specific_time,q1.color,q1.pic_url,q1.group_id,q1.title,q1.source_url,q2.time,q1.hongbao_id FROM (SELECT q3.special_id,q3.specific_time,q3.time FROM ".$this->table("chat_special_rule")." q3 WHERE q3.status = 3 )q2";
		$sql = $sql." LEFT JOIN ".$this->table("chat_special")." q1 ON q2.special_id = q1.id";
		$res3 = $this->getAll($sql);
		$res5 = array();
		$time = $_SERVER['REQUEST_TIME'];
		foreach ($res3 as $k=>$v){
			$_top=$_top+15;
			if($_top+15>=85){
				$_top=1;
			}
			$hms =date("H:i:s", $res3[$k]['specific_time']);
			if(time()<=strtotime(date( 'Y-m-d '.$hms, $time))){
				$res5[$k] = $res3[$k];
				$res5[$k]['top']=$_top;
				$res5[$k]['specific_time']=strtotime(date( 'Y-m-d '.$hms, $time));
			}
		}
	
		//单日
		$sql ="SELECT q2.specific_time,q1.color,q1.pic_url,q1.group_id,q1.title,q1.source_url,q2.time,q1.hongbao_id  FROM (SELECT q3.special_id,q3.specific_time,q3.time FROM ".$this->table("chat_special_rule")." q3 WHERE q3.status = 4 AND q3.specific_time>=$time )q2";
		$sql = $sql." LEFT JOIN ".$this->table("chat_special")." q1 ON q2.special_id = q1.id";
		$res4 = $this->getAll($sql);
		foreach ($res4 as $k=>$v){
			$_top=$_top+15;
			if($_top+15>=85){
				$_top=1;
			}
			$res4[$k]['top']=$_top;
		}
		// 		print_r(array_merge($res,$res2));
		$result['rule1'] = array_merge($res,$res2);
		// 		$result['rule2'] = $res2;
		$result['rule3'] = $res5;
		$result['rule4'] = $res4;
		return $result;
	}
	public function get_special_ad(){
		$time = $_SERVER['REQUEST_TIME'];
		$sql = "SELECT * FROM ".$this->table('block_content')." WHERE block_id = 20 AND ad_endtime>= $time";
		$result = $this->getAll($sql);
		foreach ($result as $k=>$v){
			$result[$k]['title'] = hy_dig_filter($v['title']);
			$result[$k]['description'] = hy_dig_filter($v['description']);
		}
		return $result;
		
	}
	public function get_cfg($key='')
	{
		if($key)
		{
			$sql="SELECT op_value FROM ".$this->table('options')." WHERE op_key='".$key."'";
			$arr=$this->getOne($sql);
				
		}
		else
		{
			$sql="SELECT * FROM ".$this->table('options')." ";
			$arr=array();
			$res=$this->getAll($sql);
			 
			if(count($res)>0)
			{
				foreach($res as $k=>$v)
				{
					$arr[$v['op_key']]=$v['op_value'];
				}
			}
		}
	
		return $arr;
	}
	public function get_comment_num($wxid){
		if($wxid){
			$sql = "SELECT count(*) FROM ".$this->table('chat_record')." WHERE 	TO_DAYS(from_unixtime(addtime)) = TO_DAYS(NOW()) AND wxid=".$wxid;
			$count = $this->getOne($sql);
		}
		return $count;
	}
	public function save_visitor($openid){
		$info['openid'] = $openid;
		$info['logintime'] = time();
		$info['IP'] = hy_getIP();
		$this->insert($info, 'chat_visitor');
	}
	
	public function updateFrontTime($frontTime){
		if($frontTime>=15){
			$sql = "UPDATE ".$this->table('options')." SET  op_value = 0 WHERE op_key='frontTime' ";
		}else{
			//记录自增
			$sql = " UPDATE ".$this->table('options')." SET  op_value = op_value+1 WHERE op_key='frontTime' ";
		}
		$this->query($sql);
	}
	public function get_box($group_id,$wxid){
		$result = array('error'=>0,"content"=>"请求失败");
		$sql="SELECT id FROM ".$this->table('box_user_record')." WHERE wxid=$wxid AND group_id= $group_id LIMIT 1";
		$res = $this->getOne($sql);
		if(!$res){//表示无数据，即第一次点击
			$sql="SELECT * FROM ".$this->table('box_group')." WHERE id = $group_id LIMIT 1";
			$group = $this->getRow($sql);
			if($group){
				$result['type'] = $group['type'];
				switch ($group['type']){
					case 1:
						$sql = "SELECT * FROM ".$this->table('box')." WHERE group_id = $group_id AND type=1 LIMIT 1";
						$box = $this->getRow($sql);
						if($box){//有数据
							$result['error'] =1;
							$result['box'] = $box;
						}
// 						$info['group_id'] = $group_id;$info['wxid'] = $wxid;$info['addtime'] = $_SERVER['REQUEST_TIME'];
// 						$info['status_id'] = $box.id;
// 						$this->insert($info, "box_user_record");
						break;
					case 2:
						$getPrize =$this->get_prize(array("group_id"=>$group_id,"wxid"=>$wxid));
						$prize = $getPrize['prize'];
						$result['prize']=$prize;
						$sql="SELECT * FROM ".$this->table('box')." WHERE id=".$getPrize['box_id']." LIMIT 1";
// 						if($prize==0){
// 							$sql="SELECT * FROM ".$this->table('box')." WHERE group_id = $group_id AND type=3 LIMIT 1";
// 						}else{
// 							$sql="SELECT * FROM ".$this->table('box')." WHERE group_id = $group_id AND prize = $prize AND type=2 LIMIT 1";
// 						}
						$box = $this->getRow($sql);
						if($box){//有数据
							$result['error'] =1;
							$result['box'] = $box;
						}
						$info['group_id'] = $group_id;$info['wxid'] = $wxid;$info['addtime'] = $_SERVER['REQUEST_TIME'];
						$info['status_id'] = $box['id'];$info['box_id'] =$box['id'];
						$this->insert($info, "box_user_record");
						break;
					case 3:
						$getPrize =$this->get_prize(array("group_id"=>$group_id,"wxid"=>$wxid));
						$prize = $getPrize['prize'];
						$result['prize'] = $prize;
						$sql="SELECT * FROM ".$this->table('box')." WHERE id=".$getPrize['box_id']." LIMIT 1";
						$box = $this->getRow($sql);
						if($box){//有数据
							$result['error'] =1;
							$result['box'] = $box;
						}
						if($prize!=0){//获取信息框
							$sql = "SELECT * FROM ".$this->table('box')." WHERE group_id = $group_id AND type=1 LIMIT 1";
							$getinfo = $this->getRow($sql);
							if($getinfo){//有数据
								$result['info'] = $getinfo;
							}
						}
						$info['group_id'] = $group_id;$info['wxid'] = $wxid;$info['addtime'] = $_SERVER['REQUEST_TIME'];
						$info['status_id'] = $box['id'];$info['box_id'] =$box['id'];
						$this->insert($info, "box_user_record");
						break;
				}
			}
		}else{
			$result = $this->get_box_is_exist($group_id, $res);
		}
		return $result;	
	}
	//二次登陆
	public function get_box_is_exist($group_id,$box_record_id){
		$result = array('error'=>0,"content"=>"请求失败");
		$sql="SELECT * FROM ".$this->table('box_group')." WHERE id = $group_id LIMIT 1";
		$group = $this->getRow($sql);
		if($group){
			$result['type'] = $group['type'];
			switch ($group['type']){
				case 1:
					$sql = "SELECT * FROM ".$this->table('box')." WHERE group_id = $group_id LIMIT 1";
					$box = $this->getRow($sql);
					$result['box'] = $box;
					$result['error'] =2;
					$result['content'] = "关于本次活动，您的详细信息已填写！";
					break;
				case 2:
					$sql =" SELECT box_id FROM ".$this->table("box_user_record")." WHERE id=$box_record_id LIMIT 1";
					$box_id = $this->getOne($sql);//获取中奖信息
					$sql="SELECT * FROM ".$this->table('box')." WHERE id=$box_id LIMIT 1";
					$box = $this->getRow($sql);
					$result['prize']=$box['prize'];
					if($box){//有数据
						$result['error'] =2;
						$result['content'] = "您已抽奖！";
						$result['box'] = $box;
					}
					break;
				case 3:
					$sql =" SELECT box_id,status_id FROM ".$this->table("box_user_record")." WHERE id=$box_record_id LIMIT 1";
					$ids = $this->getRow($sql);
					$sql="SELECT type FROM ".$this->table('box')." WHERE id=".$ids['status_id']." LIMIT 1";
					$type = $this->getOne($sql);
					$result['statusType']=$type;
					$sql="SELECT * FROM ".$this->table('box')." WHERE id=".$ids['status_id']." LIMIT 1";
					$box = $this->getRow($sql);
					if($type==1){//个人信息框（完结）
						$sql = "SELECT * FROM ".$this->table('box')." WHERE id = ".$ids['box_id']." LIMIT 1";
						$box = $this->getRow($sql);//获奖的外链
						$result['box'] = $box;
						$result['error'] =2;
						$result['content'] = "关于本次活动，您的详细信息已填写！";
						
					}elseif($type==2){//奖项框
						$sql = "SELECT * FROM ".$this->table('box')." WHERE id = ".$ids['box_id']." LIMIT 1";
						$box = $this->getRow($sql);//获奖的外链
						$result['error'] =2;
						$result['box'] = $box;
						$result['prize']=$box['prize'];
						$result['content'] = $box['name'];
						if($box['prize']!=0){//获取信息框
							$sql = "SELECT * FROM ".$this->table('box')." WHERE group_id = $group_id AND type=1 LIMIT 1";
							$info = $this->getRow($sql);
							if($info){//有数据
								$result['info'] = $info;
							}
						}
					}elseif($type==3){//谢谢
						$result['error'] =2;
						$result['box'] = $box;
					}
					break;
			}
		}
		return $result;
	}
	
	public function save_info($info){
		$result = array("error"=>0,"content"=>"保存失败");
		$sql="SELECT id FROM ".$this->table('box_user_record')." WHERE wxid=".$info['wxid']." AND group_id= ".$info['group_id']." LIMIT 1";
		$res = $this->getOne($sql);
		if(!$res){//不存在
			$insert = $this->insert($info, "box_user_record");
			if($insert){
				$result['error'] = 1;
				$result['content'] = "保存成功";
			}
		}else{//存在
			$update = $this->update($info, array("id"=>$res,"table"=>"box_user_record"));
			if($update){
				$result['error'] = 1;
				$result['content'] = "保存成功";
			}
		}
		return $result;
	}
	public function get_kubi_chest()
	{
		$sql="SELECT * FROM ".$this->table('kubi_total')." as p1  limit 1 ";
		$result=$this->getRow($sql);
		$joinnums = $result['joinnums'];
		$prizenums = $result['prizenums'];
		if(floor($joinnums/350)>$result['prize1'] &&$result['prize1'] < 200 )
		{
			$next = 400;
		}
		elseif(floor($joinnums/70)>$result['prize2'] &&$result['prize2'] < 1000 )
		{
			$next = 280;
		}
		elseif(floor($joinnums/18)>$result['prize3'] &&$result['prize3'] < 4000 )
		{
			$next = 170;
		}
		elseif($result['prize4'] < 64800 )
		{
			$next = 80;
		}
		else
		{
			$next = 0;
		}
	
	
		// 		$next = 0;
		return $next;
	}
	/**
	 * 
	 * @param unknown $cfg  group_id 弹框组id   wxid 用户id 
	 * @return unknown flag （new 新记录  old 已参与） prize 奖项排序  box_id 弹框项id status_id 流程状态
	 */
	
	
	public function get_prize($cfg=array())
	{
		
		
		
		//参与记录
		$sql = "  SELECT p1.* , p2.totalnums FROM  ".$this->table('box_user_record')." AS p1  ".
				"  LEFT JOIN  ".$this->table('box_group')." AS p2 ON p2.id = p1.group_id ".
				" WHERE p1.group_id = '".$cfg['group_id']."' AND  wxid='".$cfg['wxid']."'";
		
		$record = $this->getRow($sql);
		
		//是否已有记录
		if($record)
		{
			//弹框项
			$sql = "  SELECT p1.* , p2.totalnums , p2.joinnums FROM  ".$this->table('box')." AS p1 "
						." WHERE p1.id = '".$record['box_id']."'   ";
			
			$box = $this->getRow($sql);
			
			 $res['prize'] = $box['prize'];
			 $res['box_id'] = $box['box_id'];
			 $res['status_id'] = $box['status_id'];
			 $res['flag'] = $box['old'];
			 return $res;
		}
		
		
		//弹框组
		$sql = "  SELECT * FROM ".$this->table('box_group').
				" WHERE id = '".$cfg['group_id']."' ";
		
		$box = $this->getRow($sql);
		
		$sql = " SELECT * FROM  ".$this->table('box')." AS p1 "
					." WHERE p1.group_id = '".$cfg['group_id']."'  and prize >0  and type=2 order by prize   ";
		
		$boxs = $this->getAll($sql);
		
		//预计参与人数
		$totalnums = $box['totalnums'];
		
// 		实际参与人数
		$joinnums = $box['joinnums'];
// 		echo "<pre>";
// 		var_dump($boxs);
		
		

			
	
		//循环判断是否中奖
		foreach ($boxs as $k => $v )
		{
				// 每eachnums个人将产生1个中奖者
				$eachnums = 	ceil($totalnums/($totalnums*$v['pby']/100));		
				
				//该奖项限制中奖人数
				$limitnums = $v['limitnums'];
				
				//该奖项实际中奖人数
				$prizenums = $v['joinnums'];
				
				//异常中断，跳出循环
				if($eachnums==0 || $limitnums==0)
				{
					break;
				}
				
				//是否中奖，中奖则马上return
				if($v['pby']==100||(floor($joinnums/$eachnums)>$prizenums &&$prizenums < $limitnums))
				{
					//记录自增
					$sql = " UPDATE ".$this->table('box_group')." SET  joinnums = joinnums+1 WHERE id = '".$cfg['group_id']."'";
						
					$this->query($sql);
					
					$sql = " UPDATE ".$this->table('box')." SET  joinnums = joinnums+1 WHERE id = '".$v['id']."'";
					
					$this->query($sql);
					
					$res['box_id'] = $v['id'];
					$res['status_id'] = $v['id'];
					$res['prize'] = $v['prize'];
					$res['flag'] = 'new';
					
					
					
					return $res;
					//break;
				}
				
		}
		
		//谢谢参与弹框项
		$sql = " SELECT * FROM  ".$this->table('box')." AS p1 "
				." WHERE p1.group_id = '".$cfg['group_id']."'  and type =3 limit 1   ";
		
		$thanks = $this->getRow($sql);
		
		if(!$thanks)
		{
			$sql = " SELECT * FROM  ".$this->table('box')." AS p1 "
					." WHERE p1.group_id = '".$cfg['group_id']."' and p1. type =2  order by p1.prize desc ";
			
			$thanks = $this->getRow($sql);
			
		}
		
		//记录自增
		$sql = " UPDATE ".$this->table('box_group')." SET  joinnums = joinnums+1 WHERE id = '".$cfg['group_id']."'";
		
		$this->query($sql);
			
		$sql = " UPDATE ".$this->table('box')." SET  joinnums = joinnums+1 WHERE id = '".$thanks['id']."'";
			
		$this->query($sql);
		
		$res['box_id'] = $thanks['id'];
		$res['status_id'] = $thanks['id'];
		$res['prize'] = 0 ;
		$res['flag'] = 'new';
		return $res;

	}
	public function get_luckyDraw($id){
		$sql = "SELECT lottery_id FROM ".$this->table('lucky_info')." WHERE id = $id";
		$result =  $this->getOne($sql);
		return $result;
	}
	
	public function get_now_hongbaoId(){
		$title = date('md',time())."-首页红包";
		$sql = "SELECT id FROM ".$this->table('lucky_info')." WHERE title='".$title."' and status =1 LIMIT 1";
		return $this->getOne($sql);
	}
	
	public function get_url($id){
		$sql = "SELECT url FROM ".$this->table('home_url')." WHERE id=$id LIMIT 1";
		$url = $this->getOne($sql);
		if($url){
			return $url;
		}else{
			return false;
		}
	}
	
	public function get_home_url(){
		$sql = "SELECT * FROM ".$this->table('home_url')." WHERE img!='' ";
		return  $this->getAll($sql);
		
	}
}
	
	